package org.neuedu.ssmp.crm.service.impl;

import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper;
import org.neuedu.ssmp.crm.entity.Area;
import org.neuedu.ssmp.crm.entity.vo.ResponseEntity;
import org.neuedu.ssmp.crm.mapper.AreaMapper;
import org.neuedu.ssmp.crm.service.IAreaService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author MoonHolder
 * @since 2019-12-09
 */
@Service
public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements IAreaService {

    @Override
    public ResponseEntity addArea(Area area) {
        Area one = new LambdaQueryChainWrapper<>(baseMapper).eq(Area::getName, area.getName()).one();
        if (Objects.isNull(one)){
            if (baseMapper.insert(area) != 0){
                return ResponseEntity.ok("添加成功！");
            }
            return ResponseEntity.error("出错了!");
        }
        return ResponseEntity.error("数据已存在，添加失败！");
    }
}
